package com.imufe.chemicalenterprisedangerwarning.security;

import com.alibaba.fastjson.JSON;
import com.imufe.chemicalenterprisedangerwarning.common.InfoCode;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 退出登录
 * @author BaiBan
 * @since 2022/10/15
 */
@Component
public class CustomizeLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        ResponseEntity<Object> result = ResponseEntity.fail(InfoCode.USER_ACCOUNT_USE_BY_OTHERS);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(result));
    }
}
